package algorithm.structure.tree.br;

import algorithm.structure.tree.common.NodeKeySYT;
import algorithm.structure.tree.inter.BaseNodeSYT;


public class BRNodeSYT implements BaseNodeSYT{
	public static final String NODE_COLOR_BLACK = "SYT_NODE_COLOR_BLACK";
	public static final String NODE_COLOR_RED = "SYT_NODE_COLOR_RED";
	
	private BRNodeSYT leftChild;
	private BRNodeSYT rightChild;
	private BRNodeSYT parent;
	private NodeKeySYT nodeKey;
	private int size;
	private boolean isNil;
	private String color = BRNodeSYT.NODE_COLOR_BLACK;
	
	private BRNodeSYT(){
	}
	public BRNodeSYT getLeftChild() {
		return leftChild;
	}
	public NodeKeySYT getNodeKey() {
		return nodeKey;
	}
	public BRNodeSYT getParent() {
		return parent;
	}
	public BRNodeSYT getRightChild() {
		return rightChild;
	}
	public String getColor() {
		return color;
	}
	public void setColor(String color) {
		try{
			if(isNil){
				throw new RuntimeException("Nil node's color can not be changed");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		this.color = color;
	}
	public void setLeftChild(BRNodeSYT leftChild) {
		this.leftChild = leftChild;
	}
	public void setRightChild(BRNodeSYT rightChild) {
		this.rightChild = rightChild;
	}
	public void setParent(BRNodeSYT parent) {
		this.parent = parent;
	}
	public void setNodeKey(NodeKeySYT nodeKey) {
		this.nodeKey = nodeKey;
	}
	public boolean isNil() {
		return isNil;
	}
	private void setNil(boolean isNil){
		this.isNil = isNil;
	}
	public static BRNodeSYT getNilNode(){
		BRNodeSYT node = new BRNodeSYT();
		node.setNil(true);
		node.setSize(0);
		return node;
	}
	public static BRNodeSYT getNode(){
		BRNodeSYT node = new BRNodeSYT();
		node.setLeftChild(getNilNode());
		node.setRightChild(getNilNode());
		node.setParent(getNilNode());
		node.setNil(false);
		node.setSize(1);
		node.setColor(NODE_COLOR_RED);
		return node;
	}
	
	public static void main(String[] args){
		BRNodeSYT ndoe = BRNodeSYT.getNode();
		ndoe.setColor("dsads");
	}
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	public void increaseSize() {
		size++;
	}
	public void decreaseSize() {
		size--;
	}
}
